{{- if .Values.privileges.useServiceAccount -}}
apiVersion: v1
kind: ServiceAccount
metadata:
  name: {{ include "meterpreter.fullname" . }}
  labels:
    {{- include "meterpreter.labels" . | nindent 4 }}

---
{{- if ne .Values.privileges.bindClusterRole "" -}}
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: {{ include "meterpreter.fullname" . }}
  labels:
    {{- include "meterpreter.labels" . | nindent 4 }}
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: {{ .Values.privileges.bindClusterRole }}
subjects:
  - kind: ServiceAccount
    name: {{ include "meterpreter.fullname" . }}
    namespace: {{ .Release.Namespace }}
{{- end -}}
{{- end -}}
